<template>
    <div class="table">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-date"></i>{{$route.name}}
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="handle-box">
            <el-input placeholder="输入关键字" class="search" v-model="searchKey"></el-input>
            <el-button type="primary" icon="search" @click="search">搜索</el-button>
        </div>
        <div>
          <el-table :data="dataSource" border fit style="width: 100%">
                <el-table-column prop="user_name" label="姓名" show-overflow-tooltip>
                </el-table-column>
                <el-table-column prop="user_tel" label="联系电话" show-overflow-tooltip>
                </el-table-column>
          </el-table>
        </div>
        <div class="block">
            <el-pagination @current-change="handleCurrentChange" :current-page="page.number" 
            layout="total, prev, pager, next, jumper" :total="page.total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import { notification } from "../../server/getDate.js";
import { mapState, mapActions } from 'vuex'
const { adverUser } = notification
export default {
    data() {
        return {
            dialogFormVisible: false,
            title: '',
            currentId: '',
            addForm: {},
            formLabelWidth: '120px',
            searchKey: '',
        }
    },
    created() { 
        this.currentId = this.$route.query.id
        console.log(this.currentId)
        this.getList(1)
    },
    computed: mapState({
        dataSource: state => state.Notice.adverUser,
        page: state => state.Notice.adverUserPage
    }),
    methods: {
        ...mapActions(['saveAdverUser']),
        getList(number) {
            const params = {
                id: this.currentId,
                page: number,
                pageSize: 10
            }
            if (this.searchKey !== '') {
                params.searchKey = this.searchKey
            }
            adverUser({ ...params }).then(res => {
                if (res.code === '000000') {
                    this.saveAdverUser({
                        ...res,
                        number
                    })
                } else {
                    this.$message.error(res.message)
                }
            }, err => this.$message.error(err.message) )
        },
        search() {
            this.getList(this.page.number)
        },
        handleCurrentChange(val) {
            this.getList(val)
        }
    }
}
</script>
<style lang="scss" scoped>
.handle-box {
  margin-bottom: 1%;
  .search {
    width: 30%;
  }
}

.block {
  text-align: center;
  margin-top: 1%;
}
</style>
